<template>
  <div>
    <div class="page_space">
      <input-card class="mt-15">
        <inputItem
          v-model="params.billNo"
          :content='params.billNo'
          title="采样编号"
          tip="请输入采样编号"
          type="input"
        />
        <inputItem
          v-model="params.businessVarietyName"
          :content='params.businessVarietyName'
          title="样品名称"
          tip="请输入样品名称"
          type="input"
        />
        <inputItem
          v-model="params.businessVarietyCode"
          :content='params.businessVarietyCode'
          title="样品自编号"
          tip="请输入样品自编号"
          type="input"
        />
        <inputItem
          v-model="params.intercourseEnterpriseNameLike"
          :content='params.intercourseEnterpriseNameLike'
          title="经营主体"
          tip="请输入经营主体"
          type="input"
        />
        <inputItem
          v-model="params.billDate"
          :content="params.billDate"
          title="采样日期"
          tip="请选择采样日期"
          type="select"
          @select="show = true"
        />
      </input-card>
    </div>
    <div class="btn_wrap">
      <button class="btn default middle" @click="reset">重置</button>
      <button class="btn middle" @click="submit">提交</button>
    </div>

    <van-popup v-model="show" position="bottom" :round="true">
      <van-datetime-picker
        v-model="currentDate"
        type="date"
        title="选择年月日"
        visible-item-count="3"
      />
      <div class="btn_box">
        <button class="btn large" @click="submitTime">确定</button>
      </div>
    </van-popup>
  </div>
</template>

<script>
import inputCard from '@/components/input-card/card'
import inputItem from '@/components/input-card/item'
import { ParseDate } from '@/utils'
import { mutations } from '@/observable'

export default {
  name: 'samplingSearch',
  components: {
    inputCard,
    inputItem
  },
  data() {
    return {
      show: false,
      currentDate: new Date(),
      params: {
        intercourseEnterpriseNameLike: '', // 经营主体
        billDate: '', // 采样日期
        billNo: '',
        businessVarietyName: '',
        businessVarietyCode: ''
      },
      lastPage: ''
    }
  },
  created() {
    if (this.$route.query.lastPage) {
      this.lastPage = this.$route.query.lastPage
    }
    let search = decodeURIComponent(this.$route.query.searchInfo)
    console.log('dddddd', JSON.parse(search))
    if (search !== '{}') {
      this.params = JSON.parse(search)
    }
  },
  methods: {
    // 重置
    reset() {
      for (let item in this.params) {
        this.params[item] = ''
      }
    },
    // 确定-时间
    submitTime() {
      this.show = false
      let formatTime = ParseDate(this.currentDate)
      this.params.billDate = formatTime
    },
    // 提交
    submit() {
      // console.log(this.params)
      // let name = ''
      // if (this.lastPage === 'samplingLedger') {
      //   name = 'samplingLedger'
      // } else if (this.lastPage === 'samplingTest') {
      //   name = 'samplingTest'
      // }
      mutations.setSamplingSearch(this.params)
      this.$router.go(-1)
      // this.$router.replace({
      //   name,
      //   query: {
      //     searchInfo: encodeURIComponent(JSON.stringify(this.params))
      //   }
      // })
    }
  }
}
</script>
